const state = {
    funArray: [{
        name: '对字符串进行MD5加密',
        str: "md5('string')",
        functionString: `
var md5 = function (str) { 
    var md5 = NodeCrypto.createHash("md5");
    var md5Sum = md5.update(str);
    var result = md5Sum.digest("hex");
    return result;
}
        `,
    }, {
        name: '生成GUID(随机生成)',
        str: "Guid()",
        functionString: `
var Guid = function () {
    var guid = '';
    for (var i = 1; i <= 32; i++) {
        var n = Math.floor(Math.random() * 16.0).toString(16);
        guid += n;
        if ((i == 8) || (i == 12) || (i == 16) || (i == 20))
            guid += '-';
    }
    return guid;
};
        `,
    }, {
        name: '生成UUID(随机生成)',
        str: 'UUID()',
        functionString: `
var UUID = function () { 
    return uuid.v1();
}
        `,
    }, {
        name: '读取全局缓存',
        str: "getCache('key')",
        functionString: `
var getCache = function (key) { 
    if (window.hasOwnProperty('__GlobalCache__') && window.__GlobalCache__.hasOwnProperty(key) ) {
        return  window.__GlobalCache__[key];
    } else {
        return null;
    }
}
        `,
    }, {
        name: '写入全局缓存',
        str: "setCache('key','value')",
        functionString: `
var setCache = function (key,value) { 
    if (!window.__GlobalCache__){
        window.__GlobalCache__ = {};
    };
    window.__GlobalCache__[key] = value;
    store.dispatch('cache/setFromCode',{
        key : key,
        value : value
    });
}
        `,
    }],
};

const getters = {};
const mutations = {};
const actions = {
    creatNewFun(context, object) {
        context.state.funArray.push(object);
    },
    deleteFun(context, index) {
        context.state.funArray.splice(index, 1);
    },
    updatedFun(context, index, object) {
        context.state.funArray[index] = object;
    },
};

export default {
    namespaced: true,
    state,
    getters,
    mutations,
    actions
}